<?php
namespace app\admin\controller;

use app\common\model\Cate;
use app\common\model\Article;
class Init extends Base
{
    public function index()
    {
        if($this->cms==null){
            exit("error");
        }
        $catelist=model("cate")->select();
        $_articlelist=[];
        foreach ($catelist as $cate){
            if(model("cate")->where("upid",$cate['id'])->count()==0){
                for($i=0;$i<26;$i++){
                    $_articlelist[]=$this->getarticle($i,$cate['id']);
                }
                echo $cate['name']."<br/>";
            }
        }

        //处理文章
        $article=new Article();
        $article->saveAll($_articlelist);
        return "initsueecss";
    }

    public function del(){
        $article=model("article");
        $article->destroy(["cms_id"=>$this->cms['id']],true);
        return "delsucces";
    }



    private function getarticle($i,$cate_id){
        return  [
            "title"=>"文章标题$i",
            "author"=>"商倍益",
            "thumb"=>"58e8717f45a2b.jpg",
            "content"=>"<p>这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充这里是商倍益CMS系统内容填充</p>",
            "cms_id"=>$this->cms['id'],
            "cate_id"=>$cate_id
        ];
    }
}
